package org.wishwork.api.express.query;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;
import org.wishwork.api.ExtendBase;
import org.wishwork.exception.ExceptionEnum;
import org.wishwork.exception.JSTException;

import java.util.List;

/**
 * @description: 发货信息查询
 * @author: WangYX
 * @create: 2022-04-13 09:19
 * @Version: 1.0.0
 **/
@EqualsAndHashCode
@Getter
@ToString
public class ExpressQueryRequest extends ExtendBase {

    /**
     * 店铺编号
     */
    private Integer shopId;

    /**
     * 日期类型，默认发货时间，0=修改时间，1=制单日期，2=订单日期，3=发货时间
     */
    private Integer dateType;

    /**
     * 平台订单编号,最多20
     */
    private List<String> soIds;

    protected ExpressQueryRequest(Integer pageIndex, Integer pageSize, String modifiedBegin, String modifiedEnd,
                                  Integer shopId, Integer dateType, List<String> soIds) {
        super(pageIndex, pageSize, modifiedBegin, modifiedEnd);
        this.shopId = shopId;
        this.dateType = dateType;
        this.soIds = soIds;
    }


    public static Builder builder() {
        return new Builder();
    }

    @Override
    public Builder toBuilder() {
        return new Builder().pageIndex(this.pageIndex).pageSize(this.pageSize)
                .modifiedBegin(this.modifiedBegin).modifiedEnd(this.modifiedEnd)
                .shopId(this.shopId).dateType(this.dateType).soIds(this.soIds);
    }

    public static class Builder extends ExtendBase.Builder<Builder, ExpressQueryRequest> {
        private Integer shopId;
        private Integer dateType;
        private List<String> soIds;

        @Override
        public Builder modifiedBegin(String modifiedBegin) {
            this.modifiedBegin = modifiedBegin;
            return this;
        }

        @Override
        public Builder modifiedEnd(String modifiedEnd) {
            this.modifiedEnd = modifiedEnd;
            return this;
        }

        @Override
        public Builder pageIndex(Integer pageIndex) {
            this.pageIndex = pageIndex;
            return this;
        }

        @Override
        public Builder pageSize(Integer pageSize) {
            this.pageSize = pageSize;
            return this;
        }

        public Builder shopId(Integer shopId) {
            this.shopId = shopId;
            return this;
        }

        public Builder dateType(Integer dateType) {
            this.dateType = dateType;
            return this;
        }

        public Builder soIds(List<String> soIds) {
            if (soIds != null) {
                if (soIds.size() > 20) {
                    throw new JSTException(ExceptionEnum.USER_ERROR_A0420, "平台订单编号,最多20!");
                }
            }
            this.soIds = soIds;
            return this;
        }


        @Override
        public ExpressQueryRequest build() {
            this.pageIndex = this.pageIndex == null ? 1 : this.pageIndex < 0 ? 1 : this.pageIndex;
            this.pageSize = this.pageSize == null ? 30 : this.pageSize < 0 ? 30 : this.pageSize;
            modifiedTimeHandle(7);
            return new ExpressQueryRequest(this.pageIndex, this.pageSize, this.modifiedBegin, this.modifiedEnd,
                    this.shopId, this.dateType, this.soIds);
        }
    }


}
